#region Directives
using System;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;

using VisualStudioSensor;
using TeamFoundationServerSensor;
#endregion
/// <summary>
/// Web Service Endpoint for the <seealso href="BranchMovedEvent"/>
/// </summary>
/// <remarks>
/// To Register this Notification Endpoint you will need to use the <seealso href="http://blogs.msdn.com/psheill/archive/2006/02/01/522386.aspx">BisSubscribe.exe</seealso> tool. 
/// For more information about Team Foundation Server Notifications <seealso href="http://blogs.msdn.com/buckh/archive/2006/04/10/event_filtering.aspx"/>
/// </remarks>
[WebService(Namespace = "http://schemas.conchango.com/TeamFoundation/2005/06/Services/Notification/Extensibility", Description = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class BranchMovedEndpoint : TeamFoundationServerSensor.EndpointBase {

    /// <summary>
    /// Endpoint required to accept incoming <see href="BranchMovedEvent"/> notifications
    /// </summary>
    /// <param name="eventXml">Serialized version of the <see href="BranchMovedEvent"/></param>
    /// <param name="tfsIdentityXml">Serialized version of <see href="TFSIdentity"/></param>
    /// <returns>True if method succeeded in reading data. False otherwise.</returns>
    [WebMethod]
    [SoapDocumentMethod("http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03/Notify", RequestNamespace = "http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03")]
    public override Boolean Notify(string eventXml, string tfsIdentityXml) {
        BranchMovedEvent branchedMovedEvent = this.CreateInstance<BranchMovedEvent>(eventXml);
        TFSIdentity tfsIdentity = this.CreateInstance<TFSIdentity>(tfsIdentityXml);

        Boolean success = false;

        try {

            // Common data collected.
            Dictionary<string, string> pMap_DevEvent = new Dictionary<string, string>();
            pMap_DevEvent.Add("SubType", "Branch Move");

            // Extra Useful information to send
            pMap_DevEvent.Add("ProjectURI", branchedMovedEvent.ProjectUri);
            pMap_DevEvent.Add("OldParentURI", branchedMovedEvent.OldParentUri);
            pMap_DevEvent.Add("NewParentURI", branchedMovedEvent.NewParentUri);
            
            // Determine what type of data is in the artifact
            SensorShellProxy.TheInstance.SendDevEventData("StructureChange",
                branchedMovedEvent.NodeUri,
                pMap_DevEvent);
            success = true;
        }
        catch (Exception e) {
            Logger.TheInstance.Log("Error sending branch move data. Data will be lost. " + e, LogLevel.Error);
        }

        return success;
    }
}